package org.gd.spring.hibernate.entity;

import com.google.gson.GsonBuilder;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "STOCK")
@Access(value = AccessType.PROPERTY)
public class Stock implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer stockId;
    private String stockCode;
    private String stockName;
    private Emb emb;
    private User user;

    public Stock() {
    }

    public Stock(String stockCode, String stockName) {
        this.stockCode = stockCode;
        this.stockName = stockName;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "STOCK_ID", unique = true, nullable = false)
    public Integer getStockId() {
        return this.stockId;
    }

    public void setStockId(Integer stockId) {
        this.stockId = stockId;
    }

    @Column(name = "STOCK_CODE", unique = false, nullable = false, length = 10)
    public String getStockCode() {
        return this.stockCode;
    }

    public void setStockCode(String stockCode) {
        this.stockCode = stockCode;
    }

    @Column(name = "STOCK_NAME", unique = false, nullable = false, length = 20)
    public String getStockName() {
        return this.stockName;
    }

    public void setStockName(String stockName) {
        this.stockName = stockName;
    }

    @Column
    @Embedded
    //@AttributeOverride(column = @Column(name = "ENABLE"), name = "enable")
    public Emb getEmb() {
        return emb;
    }

    public void setEmb(Emb emb) {
        this.emb = emb;
    }

    @ManyToOne
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String toString() {
        return new GsonBuilder()
                .setPrettyPrinting()
                .create()
                .toJson(this);
    }
}

